Add genie_overrides to QairtEncapsulation for GenAIConfig customization#2469
Draft
qti-kromero wants to merge 2 commits into
Draft
Add genie_overrides to QairtEncapsulation for GenAIConfig customization#2469qti-kromero wants to merge 2 commits into
qti-kromero wants to merge 2 commits into
Conversation
Introduce a genie_overrides PassConfigParam that deep-merges user-supplied fields into the GenAIConfig before LLMContainer.export() bakes them into the Genie DLC. This allows callers to override any GenAIConfig field (engine config, positional encoding, etc.) without modifying QairtGenAIBuilder or QairtPipelinePass. Nested dicts are merged recursively so only the specified keys are changed; all other values set by the upstream builder pass are preserved.
| container: qairt_genai.LLMContainer = qairt_genai.LLMContainer.load(model.model_path) | ||
|
|
||
| if config.genie_overrides: | ||
| gen_ai_cfg = container._gen_ai_config |
| gen_ai_cfg = container._gen_ai_config | ||
| current = gen_ai_cfg.model_dump(mode="json", by_alias=False, exclude_none=True) | ||
| merged = _deep_merge(current, config.genie_overrides) | ||
| container._gen_ai_config = gen_ai_cfg.model_validate(merged) |
| "kv_dim": None, | ||
| "positional_encoding": {"type": "rope", "rope_dim": 64}, | ||
| } | ||
| mock_container._gen_ai_config.model_dump.return_value = initial_gen_ai_state |
| encap_pass.run(mock_qairt_model, str(output_path)) | ||
|
|
||
| # model_dump was called to capture current state | ||
| mock_container._gen_ai_config.model_dump.assert_called_once_with(mode="json", by_alias=False, exclude_none=True) |
…ensions customization Adds a backend_extensions_override PassConfigParam that is deep-merged into the LLMContainer's existing _backend_extensions_config before the Genie DLC is produced. Uses the raw JSON key names (hyphens) as they appear in backend_extensions.json. Nested dicts are merged recursively so only specified keys are overridden; all other defaults set by the builder are preserved. If the container has no existing backend extensions config, the override becomes the entire config. Includes 4 tests covering default config presence, merge into existing config, merge from empty, and no-op when override is None. Also drops one fragile identity assertion from the existing genie_overrides test.
| "kv_dim": 128, | ||
| "positional_encoding": {"type": "rope", "rope_dim": 64, "rope_theta": 500000.0}, | ||
| } | ||
| mock_container._gen_ai_config.model_validate.assert_called_once_with(expected_merged) |
|
|
||
| encap_pass.run(mock_qairt_model, str(output_path)) | ||
|
|
||
| mock_container._gen_ai_config.model_dump.assert_not_called() |
| (model_path / "generation_config.json").write_text(json.dumps({"eos_token_id": 2})) | ||
|
|
||
| mock_container = MagicMock() | ||
| mock_container._backend_extensions_config = {"context": {"n-threads": 6, "kv-cache-size": 512}} |
| encap_pass.run(mock_qairt_model, str(output_path)) | ||
|
|
||
| # n-threads overridden; kv-cache-size from original preserved | ||
| assert mock_container._backend_extensions_config == {"context": {"n-threads": 4, "kv-cache-size": 512}} |
| def test_encapsulation_backend_extensions_override_from_empty(tmp_path, mock_qairt_model, mock_qairt_modules): | ||
| """When the container has no existing backend extensions config, the override becomes the config.""" | ||
| mock_container = MagicMock() | ||
| mock_container._backend_extensions_config = None |
| ) | ||
| encap_pass.run(mock_qairt_model, str(output_path)) | ||
|
|
||
| assert mock_container._backend_extensions_config == {"context": {"n-threads": 4}} |
| original_ext_cfg = {"context": {"n-threads": 6}} | ||
|
|
||
| mock_container = MagicMock() | ||
| mock_container._backend_extensions_config = original_ext_cfg |
| encap_pass = create_pass_from_dict(QairtEncapsulation, {"backend": "CPU"}, disable_search=True) | ||
| encap_pass.run(mock_qairt_model, str(output_path)) | ||
|
|
||
| assert mock_container._backend_extensions_config is original_ext_cfg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce a genie_overrides PassConfigParam that deep-merges user-supplied fields into the GenAIConfig before LLMContainer.export() bakes them into the Genie DLC. This allows callers to override any GenAIConfig field (engine config, positional encoding, etc.) without modifying QairtGenAIBuilder or QairtPipelinePass.
Nested dicts are merged recursively so only the specified keys are changed; all other values set by the upstream builder pass are preserved.
Describe your changes
Checklist before requesting a review
lintrunner -a(Optional) Issue link